package com.ball.dev.controller;


import com.ball.common.dtos.ResponseResult;
import com.ball.common.utils.UserContext;
import com.ball.dev.entity.po.PostLikes;
import com.ball.dev.entity.vo.PostVo;
import com.ball.dev.service.IPostLikesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 *点赞
 *
 * @author lou
 * @since 2024-03-27
 */
@RestController
@RequestMapping("/postLikes")
@RequiredArgsConstructor
public class PostLikesController {

    private final IPostLikesService postLikesService;

    @PostMapping("/addPostLikes")
    public ResponseResult addPostLikes(@RequestBody PostLikes postLikes) {
        return postLikesService.addPostLikes(postLikes);
    }

   @GetMapping("/getLikes")
    public ResponseResult getLikes() {
        //获取当前用户id
        String userId = UserContext.getUser();
        //根据用户id查询点赞信息
        List<PostLikes> postLikes = postLikesService.lambdaQuery().eq(PostLikes::getUserId, userId)
                .orderByDesc(PostLikes::getCreateTime).list();
        //将点赞信息转换为PostVo
        new ArrayList<PostVo>();
        return ResponseResult.okResult(postLikes);
    }





}
